<template>
	<view>
		<view class="btnView">
			<button class="addbnt" @click="toPlan">新增</button>
		</view>
		<view>
			<!-- 插入模式 -->
			<uni-calendar class="uni-calendar--hook" :selected="selected" 
				:showMonth="false" @monthSwitch="monthSwitch" />
		</view>
		<view >
			<uni-list>
				<uni-list-item v-for="(item,index) in selected" :key="item.date" 
					:title="item.data.bisWhfaHwrq" :note="translateDictFwlx(item.data.bisWhfaFwlx)">
		
					<template v-slot:footer>
						<view class="btnView">
							<button class="addbnt" @click="delPlan(item)">删除</button>
							<button class="addbnt" @click="toEditPlan(item)">修改</button>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script lang="ts">
	import { route,routeMixin } from "@/route/Route"
	import { planService } from "@/service/PlanService"
	
	export default {
		mixins: [routeMixin],
		data() {
			return {
				signedData: {},
				selected: [],
				currentDate: "",
				selectedMonth: "",
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: "方案列表"
			})
		},
		methods: {
			routeParameterEvent(data) {
				this.signedData = data
				this.routeParameter = data 
				console.log(data)
				planService.queryDyqx({id: this.signedData.zhsq.bisZhsqId},(res)=>{
					this.currentDate = res.currentDate
					this.getFwfaList(this.selectedMonth)
				})
			},
			translateDictFwlx(code){
				let value = ""
				switch(code){
					case "94" :
						value = "生活服务"
						break;
					case "95" :
						value = "医疗护理"
						break;
					default:
						
				}
				return value;
			},
			toPlan(){
				route.navigateTo({name:'plan',parameter:this.routeParameter})
			},
			toEditPlan(item){
				route.navigateTo({name:'planEdit',parameter:item})
			},
			monthSwitch(e) {
				console.log('monthSwitchs 返回:', e)
				let year = e.year
				let month = e.month
				if(month < 10){
					month = '0' + month
				}
				this.selectedMonth = year+'-'+month
				this.getFwfaList(this.selectedMonth)
			},
			getFwfaList(bisWhfaHwrq){
					let pageReq = {  sort: "bisWhfaHwrq,DESC" }
				
				planService.list({...pageReq,bisWhfaZhsqId:this.signedData.zhsq.bisZhsqId,bisWhfaHwrq:bisWhfaHwrq},(res)=>{
					this.selected = []
					for(let fwData of res){
						this.selected = [...this.selected,{
							date: fwData.bisWhfaHwrq,
							info: this.translateDictFwlx(fwData.bisWhfaFwlx).substring(0,2),
							data: fwData
						}]
					}
				})
			},
			delPlan(item){
				console.log(item)
				let _this = this
				uni.showModal({
					title: '确认',
					content: '是否确认删除'+item.date+"的服务方案",
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确认');
							planService.deleteZhfa({id:item.data.bisWhfaId},(resp)=>{
								console.log(resp)
								_this.getFwfaList(_this.selectedMonth)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			fromRouteParameterEvent(id,data) {
				console.log(id,data)
				if(id == 1){
					this.getFwfaList(this.selectedMonth)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	.btnView{
		display: flex;
		flex-direction: row-reverse;
		padding: 18rpx;
	}
	.addbnt{
		background-color: $uni-color-primary;
		color: $uni-text-color-inverse;
		width: 150rpx;
		height: 80rpx;
		margin: 0rpx 10rpx;
		font-size: 35rpx;
	}
</style>
